package com.g2room.driving.grap.company;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.jetty.util.StringUtil;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.alibaba.fastjson.JSON;
import com.g2room.driving.grap.GenericGrap;
import com.g2room.driving.grap.life.model.po.ComShopComment;
import com.g2room.myuall.grap.ky.model.po.GrapErr;
import com.g2room.myuall.util.DbUtil;

public class GrabCtripComment {
	
	public static void main(String[] args) throws Exception{
		getTypes();
	}
	public static void getTypes() {
		try {
			Connection connection = DbUtil.getConn("life");
			Statement statement = connection.createStatement();
			String sql = "select id,type_name from life_scenery";
			ResultSet rs = statement.executeQuery(sql);
			Map<String, Integer> types =new HashMap<String, Integer>();
			List<String> types1 =new ArrayList<String>();
			while(rs.next()) {
				String cat = "";
				String cn = rs.getString("type_name");
				if(null == cn) continue;
				for(String c : cn.split(";")) {
					types.put(c, rs.getInt("id"));
					if(!c.equals("") && c.trim().length() > 1)
					types1.add(c);
				}
			}
//			System.out.println(types.toString());
			for(String key : types.keySet()) {
				System.out.println(key);
//				for(String cat : types1) {
//					if(key.contains(cat) && !key.equals(cat)) {
//						System.out.println(key + "=="+cat);
//					}
//				}
			}
			rs.close();
			statement.close();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void delErr(int id) {
		PreparedStatement grapPs = null;
		try {
			grapPs = DbUtil.getComConn().prepareStatement("delete from grap_err where id=?");
			grapPs.setInt(1, id);
			grapPs.execute();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			if(null != grapPs) {
				try {
					grapPs.close();
				} catch (SQLException e) {
					
				}
			}
		}
	}
	
	public static Map<Integer, String> getUrls(String type) {
		Map<Integer, String> map =new HashMap<Integer, String>();
		try {
			Connection connection = DbUtil.getComConn();
			Statement statement = connection.createStatement();
			String sql = "select  old_id,source_url from life_scenery";
			if(type.equals("2")) {
				sql = "select  old_id,source_url from life_scenery";
			} else if(type.equals("3")) {
				sql = "select  old_id,source_url from com_shop where kind_name='餐馆美食' or kind_name='餐馆小吃'";
			} else if(type.equals("4")) {
				sql = "select  old_id,source_url from com_shop where kind_name='购物'";
			}
			
			ResultSet rs = statement.executeQuery(sql);
			while(rs.next()) {
				map.put(rs.getInt("old_id") ,rs.getString("source_url"));
			}
			rs.close();
			statement.close();
		} catch(Exception e) {
			e.printStackTrace();
		}
		return map;
	}
	
}
